class SlaTemplate
  def initialize(cf_client)
    @cf_client = cf_client
  end

  def find_all_sla_templates()
    @cf_client.list_sla_templates || []
  end




  def create(name, instances, memsize,disksize,framework, runtime, service,app_starttime,app_stoptime,price,fine)
    raise I18n.t('sla_templates.model.name_blank') if name.blank?
    raise I18n.t('sla_templates.model.name_invalid', :name => name) if (name =~ /^[\w-]+$/).nil?
    manifest = {
        :name =>name ,
        :instances =>instances,
        :memsize => memsize,
        :disksize=>disksize,
        :service => service,
        :framework=>framework,
        :runtime=>runtime,
        :app_starttime => app_starttime,
        :app_stoptime =>app_stoptime,
        :price=>price ,
        :fine  =>fine
    }
    puts "manifest------------------------------#{manifest}-----------------------------------------------"

    @cf_client.create_sla_template(name, manifest)
  end

  def delete(name)
    raise I18n.t('sla_templates.model.name_blank') if name.blank?
    @cf_client.delete_sla_template(name)
  end



  def find(name)
    raise I18n.t('sla_templates.model.name_blank') if name.blank?
    sla_template_info = @cf_client.sla_template_info(name) || {}

    puts"find  sla_template_info =#{sla_template_info}"
    if !sla_template_info.nil?
      sla_template_info = nil
      sla_templates = find_all_sla_templates()
      sla_templates.each do |sla_template_item|
        if sla_template_item[:name] == name
          sla_template_info = sla_template_item
          break
        end
      end
    end
    sla_template_info
  end



end